<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<span style="font-size:18px;">
<html>
<head>
    <meta name="viewport" content="width=device-width, initial-scale=1">
    <link rel="stylesheet" type="text/css" href="purchase/css/bootstrap.min.css" />
    <link rel="stylesheet" type="text/css" href="purchase/css/commonly-used-show.css" />
    <script type="text/javascript" src="purchase/js/jquery.min.js"></script>
    <script type="text/javascript" src="purchase/js/bootstrap.js" ></script>

    <!--  缓存 -->
    <script type="text/javascript" src="purchase/js/jquery.cookie.js"></script>


    <c:if test="${param.id != 1}">
        <title>修改仓库信息</title>
    </c:if>

    <c:if test="${param.id == 1}">
        <title>添加仓库信息</title>
    </c:if>



</head>

<body class="mybody">

<c:if test="${user_leve == 1}">
    <jsp:include page="theTopMenuAdmin.jsp" />
</c:if>

<c:if test="${user_leve == 2}">
    <jsp:include page="theTopMenuUser.jsp" />
</c:if>


 <div class="container-fluid">
    <div class="row">


        <div class="col-md-12">
            <div class="col-md-12">
                    <div class="panel panel-primary">
                        <div class="panel-body">
                            <div class="alert alert-success">



                                <div class="container">
                                    <c:if test="${param.id == 1}">
                                        <h3 style="text-align: center">添加仓库信息</h3>
                                    </c:if>

                                    <c:if test="${param.id != 1}">
                                        <h3 style="text-align: center">修改仓库信息</h3>
                                    </c:if>

        <hr style="filter: alpha(opacity=100,finishopacity=0,style=3)" width="100%" color="#6f5999" size="3" />

        <div id="reset_form" class="container">
            <div class="form-group same-line">
                <label ><b style="color: red">*&nbsp</b>仓库编号：</label>
                <input type="text" id="warehouse_number" class="form-control edit" placeholder="请输入仓库编号" maxlength="20">

            </div>

            <div class="form-group same-line-left">
                <label ><b style="color: red">*&nbsp</b>仓库地址：</label>
                <input type="text" id="warehouse_address" class="form-control edit" placeholder="请输入仓库地址" maxlength="20">

            </div>

            <div class="form-group same-line-left">
                <label ><b style="color: red">*&nbsp</b>仓库面积：</label>
               <input type="text" id="storage_area" class="form-control edit" placeholder="请输入仓库面积" maxlength="6">

            </div>

            <div class="form-group same-line">
                <label ><b style="color: red">*&nbsp</b>货架号：</label>
                <input type="text" id="shelves" class="form-control edit" placeholder="请输入货架号" maxlength="16">

            </div>

            <div class="form-group same-line-left">
                 <label ><b style="color: red">*&nbsp</b>仓库类别：</label>
                <input type="text" id="warehouse_category" class="form-control edit" placeholder="请输入仓库类别" maxlength="16">

            </div>

            <div class="form-group same-line-left">

                <label>备注：</label>
                <textarea style="resize:none"  id="comment" rows="4" cols="50" class="form-control edit" placeholder="请输入备注"></textarea>
            </div>


        </div>

        <div style="margin-top: 30px;" class="form-group text-center same-line-clear">
            <input type="button" id="mybut" value="添加" class="btn btn-primary" onclick="addSupplie()">
            <input type="reset" value="重置" class="btn btn-danger interval" onclick="reset()">
        </div>

        <div class="text-center">
            <span id="user_messge" style="font-size:10px; color: red;"></span>
        </div>

</div>



                            </div>
                        </div>
                    </div>
                </div>
        </div>



    </div>

 </div>



<script type="text/javascript">
    var userdt = JSON.parse(sessionStorage.getItem("user"));
    if (userdt.result.userName != null){
        $("#usname").text(userdt.result.userName);
    }else {
        $("#usname").text(userdt.result.userLoginName);
    }

    var postUrlua;

    //重置文本框
    function reset(){
        var addUser = document.getElementById("reset_form");
        var ipts = addUser.getElementsByTagName("input");
        for (var i = 0; i < ipts.length; i++){
            ipts[i].value = "";
        }
    }


    if ("${param.id}" !== "1"){
        window.onload = function(){
            getWareho();
        }
        $("#mybut").val("确认修改");
        postUrlua = "${pageContext.request.contextPath}/member/updateWarehouse";

    }else {
        postUrlua = "${pageContext.request.contextPath}/member/addWarehouse";
    }


    function getWareho(){
        var postUrl = "${pageContext.request.contextPath}/member/queryWarehouse";
        var str = {
            "id": "${param.id}"
        };

        $.ajax({
            type:"post",
            url:postUrl,
            headers: {
                "Content-Type":"application/json"
            },
            data:JSON.stringify(str),
            contentType: "application/json; charset=utf-8",
            dataType:"json",
            success:function(data){
                if (data.status === 0){
                    $("#user_messge").text(data.msg);
                }else {
                    $("#warehouse_number").val(data.result.warehouseNumber);
                    $("#warehouse_address").val(data.result.warehouseAddress);
                    $("#storage_area").val(data.result.storageArea);
                    $("#shelves").val(data.result.shelves);
                    $("#warehouse_category").val(data.result.warehouseCategory);
                    $("#comment").val(data.result.comment);

                }

            },
            error:function(xhr,state,errorThrown){
                //alert("发生网络错误，错误码为：" + xhr.status)
                location.href = "${pageContext.request.contextPath}/error";
            }
        });
    }

    function addSupplie(){
        var warehouseNumber = $("#warehouse_number").val();
        var warehouseAddress = $("#warehouse_address").val();
        var storageArea = $("#storage_area").val();
        var shelves = $("#shelves").val();
        var warehouseCategory = $("#warehouse_category").val();
        var comment = $("#comment").val();


        if ($.isEmptyObject(warehouseNumber)){
            $("#user_messge").text("仓库编号不能为空");
            return;
        } else if ($.isEmptyObject(warehouseAddress)){
            $("#user_messge").text("仓库地址不能为空");
            return;
        }else if ($.isEmptyObject(storageArea)){
            $("#user_messge").text("仓库面积不能为空");
            return;
        }else if ($.isEmptyObject(shelves)){
            $("#user_messge").text("货架号不能为空");
            return;
        }else if ($.isEmptyObject(warehouseCategory)){
            $("#user_messge").text("仓库类别不能为空");
            return;
        }else {
            $("#user_messge").text("");
        }


        var str = {
            "id": "${param.id}",
            "warehouseNumber": warehouseNumber,
            "warehouseAddress": warehouseAddress,
            "storageArea": storageArea,
            "shelves": shelves,
            "warehouseCategory": warehouseCategory,
            "comment": comment
        };

        $.ajax({
            type:"post",
            url:postUrlua,
            headers: {
                "Content-Type":"application/json"
            },
            data:JSON.stringify(str),
            contentType: "application/json; charset=utf-8",
            dataType:"json",
            success:function(data){
                if (data.status === 0){
                    $("#user_messge").text(data.msg);
                }else {
                    if ("${user_leve}" === "2"){
                        reset();
                        $("#user_messge").text("添加成功");
                    }else {
                        location.href = "${pageContext.request.contextPath}/storeManagement";
                    }

                }

            },
            error:function(xhr,state,errorThrown){
                //alert("发生网络错误，错误码为：" + xhr.status)
                location.href = "${pageContext.request.contextPath}/error";
            }
        });

    }

</script>



</body>
</html>
</span>